﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;

namespace IceDog.Lib.IceDogMail
{
    class MailManager
    {
        private MailMessage _mail;
        private SmtpClient _client;

        public MailManager()
        {
            _mail = new MailMessage();
            _client = new SmtpClient();
        }

        public string SendMail()
        {
            var recipientsAddress = "hao.huang@macrowing.com";
            var subject = "SAAS用户申请";
            //var emailAddressCc = "";
            var emailAddressBcc = "335121817@qq.com";
            //var approvalUrl =
            //"https://saasaccount.macrowing.com/cloud/portalMain/SubLinkForEform?isPreview=1&pageId=7bf9c64628a54c2d830dc4394b9e6da6&eformUrl=/cloud/eform/app/LayoutPreview?appId=e16bfcd7-d541-467f-9bfc-7fa556b353cb";
            var mailContent = "xxx";
            var mail = new MailMessage();
            mail.To.Add(new MailAddress(recipientsAddress));
            mail.Subject = subject;
            //_mail.CC.Add(new MailAddress(emailAddressCc));
            mail.Bcc.Add(new MailAddress(emailAddressBcc));
            mail.IsBodyHtml = true;
            mail.Body = mailContent;
            mail.From = new MailAddress("webform@macrowing.com");
            var client = new SmtpClient("smtp.exmail.qq.com", 0);
            client.EnableSsl = false;
            client.Credentials = new NetworkCredential("webform@macrowing.com", "1qaz2WSX");
            try
            {
                client.SendAsync(mail, mail);
                return "ok";
            }
            catch (Exception e)
            {
                throw;
                return "fail";
            }
        }
    }
}
